package netty.im.server;

import org.apache.log4j.Logger;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;

public class SimpleChatServerInitializer extends ChannelInitializer<SocketChannel> {
 
	private static Logger log = Logger.getLogger(SimpleChatServerInitializer.class);  
	
    @Override
    public void initChannel(SocketChannel ch) throws Exception {
         ChannelPipeline pipeline = ch.pipeline();
 
       // pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
     /*    pipeline.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
         pipeline.addLast("encoder", new ObjectEncoder());
         pipeline.addLast("handler", new SimpleChatServerHandler());*/
         
         /**
          * http-request解码器
          * http服务器端对request解码
          */
         pipeline.addLast("decoder", new HttpRequestDecoder());
         /**
          * http-response解码器
          * http服务器端对response编码
          */
         pipeline.addLast("encoder", new HttpResponseEncoder());

         /**
          * 压缩
          * Compresses an HttpMessage and an HttpContent in gzip or deflate encoding
          * while respecting the "Accept-Encoding" header.
          * If there is no matching encoding, no compression is done.
          */
         pipeline.addLast("deflater", new HttpContentCompressor());

         pipeline.addLast("handler", new SimpleChatServerHandler());
 
        //System.out.println("SimpleChatClient:"+ch.remoteAddress() +"连接上");
        log.info("SimpleChatClient:"+ch.remoteAddress() +"连接上");
    }
}